<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>

<!--  -->
<script type="text/javascript" src="../js/jquery/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="../plug/highcharts/highcharts.js"></script>
<script>
$.extend({
	  getUrlVars: function(){
	    var vars = [], hash;
	    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	    for(var i = 0; i < hashes.length; i++)
	    {
	      hash = hashes[i].split('=');
	      vars.push(hash[0]);
	      vars[hash[0]] = hash[1];
	    }
	    return vars;
	  },
	  getUrlVar: function(name){
	    return $.getUrlVars()[name];
	  }
	});


function initCurve(id) {
	var seriesData=[];
	function getIntensityCurve(){
		arg={};
		arg['id']=id;
		
		$.ajax({
			url : '/doroodo/sys/cxSbReadStatus_Get_ByTid',
			data : arg,
			dataType : 'json',
			type: "post", 
			async:true,
			contentType: "application/x-www-form-urlencoded; charset=utf-8", 
			success : function(r) {
				getIntensityCurveCallBack(r)
			}
		});
		
	}
	function getIntensityCurveCallBack(data) {
		console.info(data);
		if(data.length<1)
		{
			//loadNullCurve();
			return;	
		}	
		seriesData[0]={name:'漏电电流',data:[]};
		seriesData[1]={name:'A相电流',data:[]};
		seriesData[2]={name:'B相电流',data:[]};
		seriesData[3]={name:'C相电流',data:[]};
		$.each(data,function(index,_data){
			
			seriesData[0].data.push([new Date(_data["saveDate"])-new Date('1970-1-1'),parseFloat(_data["leakageCurrent"])])
			seriesData[1].data.push([new Date(_data["saveDate"])-new Date('1970-1-1'),parseFloat(_data["acurrent"])])
			seriesData[2].data.push([new Date(_data["saveDate"])-new Date('1970-1-1'),parseFloat(_data["bcurrent"])])
			seriesData[3].data.push([new Date(_data["saveDate"])-new Date('1970-1-1'),parseFloat(_data["ccurrent"])])
		});
		$('#container').highcharts(
				{
					chart : {
						type : 'spline',
						zoomType:'x',
						events : {
							load : function() {
								console.info('load')
							}
						}
					},
					title : {
						text : ''
					},
					xAxis : {
						type: 'datetime',
						tickPixelInterval: 60,//x轴上的间隔 
						dateTimeLabelFormats:{
						second:'%M:%S',
						minute:'%H:%M',
						hour:'%H:%M',
						day:'%m-%d',
						week:'%Y-%m-%d',
						month:'%Y-%m',
						year:'%Y'
						},
						title:{ 
							text:null,
							align:'middle' 
						}
					},
					yAxis : {
						min:0,
						title : {
							enabled : false
						}
					},
					legend : {
						layout : 'vertical',
						align : "right",
						verticalAlign : "top",
						floating : true
					},
					tooltip : {
						enabled : true ,
						xDateFormat:'%Y-%m-%d %H:%M:%S',
						formatter : function() {
							return '<b>' + this.series.name + '</b><br/>   '
									+ Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '<br/>  电流: ' + this.y + 'A';
						} 
					},
					plotOptions : {
						line : {
							dataLabels : {
								enabled : true
							},
							enableMouseTracking : true
						}
					},
					credits : {
						enabled : false
					},
					series : seriesData
				});
	}
	getIntensityCurve();
	
}



$(function () {
	var vars=$.getUrlVars();
	$('#container').width(parseInt(vars.width)-20).height(vars.height);
	var id=vars.id;
	initCurve(id);
});

</script>
</head>
<body>
<div id="container" style="width:400px;height:200px"><h2>无数据</h2></div>
</body>
</html>